using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class Recruiters_JobDetails : System.Web.UI.Page
{
    string connectionString;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session.Contents["rcuserid"] == null)
        {
            Response.Redirect("login.aspx");
        }
        
        
        if (!IsPostBack)
        {
            try
            {    connectionString =
                    WebConfigurationManager.ConnectionStrings[
                      "RecruitVietnam"].ConnectionString;

                RegisterJavaScript();



                string jobID = "";
                jobID = Request.QueryString.Get("JobID");             
                string fromPage = Request.QueryString.Get("page");
                if (jobID != null && jobID != "")
                {
                    int recruiterID = ShowDetails(jobID);
                    if (recruiterID > 0)
                    {                         
                        AdjustData();
                    }
                    else
                    {
                        
                        hyperLinkPrint.Visible = false;
                        litError.Text = "Sorry, Job is not existing.";
                    }
                    
                }
                else
                    litError.Text = "Sorry, Job is not existing.";

            }
            catch (Exception ex)
            {
                litError.Text = ex.Message;
            }
        }
    }
    void AdjustData()
    {

        if (DetailsView1.Rows[16].Cells[0].Text != "")
            DetailsView1.Rows[16].Cells[0].Text
            = DetailsView1.Rows[16].Cells[
            0].Text.Replace("-", "<br>-");
        if (DetailsView1.Rows[18].Cells[0].Text != "")
            DetailsView1.Rows[18].Cells[0].Text =
            DetailsView1.Rows[18].Cells[
            0].Text.Replace("-", "<br>-");
    }
    void RegisterJavaScript()
    {
        Common common = new Common();
        this.ClientScript.RegisterClientScriptBlock(
        this.GetType(), "openWindow" +
        this.DetailsView1.ID,
        common.CreateScriptForPrint(this.DetailsView1.ID));
        this.hyperLinkPrint.Attributes.Add("onclick",
        "openWindow" + this.DetailsView1.ID
        + "('" + DetailsView1.ID.ToString()
        + "', 500, 500);return false;");
    }
    int ShowDetails(string jobID)
    {
        int isExisting = 0;
        try
        {
            SqlServerProvider obj =
            new SqlServerProvider();
            obj.ConnectionString =
            connectionString;
            obj.CommandText =
            "SPViewJobDetailsByRecruiter";
            obj.ParameterCollection =
            new string[2] { "@JobID", "@RecruiterID" };
            obj.ValueCollection =
            new string[2] { jobID, Session.Contents["rcuserid"].ToString() };
            obj.CommandType =
            CommandType.StoredProcedure;
            DataTable dataTable =
            obj.GetDataTable();
            if (dataTable.Rows.Count > 0)
            {
                isExisting = Convert.ToInt32(
                dataTable.Rows[0][1]);
                DetailsViewHelper objHelper =
                new DetailsViewHelper();
                objHelper.FillDataTableToDetailsView(
                dataTable, this.DetailsView1);
                literalIntro.Text =
                dataTable.Rows[0][0].ToString();
            }
        }
        catch (Exception ex)
        {
            litError.Text = ex.Message;
        }
        return isExisting;
    }
     
}
